// pages/push/sport.js
// pages/activity/historyList/historyList.js
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    color2:'#000000',
    color1:'#b6b6b6',
    playIndex: null,
    videoList: [],
    totalCount:0,/*视频总数=videolist的id数*/    
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
   
     name:'',
test:'test',
tag: false,
left:0,
indexCurrent: null
  },
  video_play:function(e) {
    var curIdx = e.currentTarget.id;
    // 没有播放时播放视频
    // console.log(curIdx)
    if (!this.data.indexCurrent) {
    this.setData({
    indexCurrent: curIdx
    })
    var videoContext = wx.createVideoContext(curIdx,this)//这里对应的视频id
    videoContext.play()
    } else {
      // 有播放时先将prev暂停，再播放当前点击的current
    var videoContextPrev = wx.createVideoContext(this.data.indexCurrent,this)
    //this是在自定义组件下，当前组件实例的this，以操作组件内 video 组件（在自定义组件中药加上this，如果是普通页面即不需要加）
    if (this.data.indexCurrent != curIdx) {
    console.log(123)
    videoContextPrev.pause()
    
    this.setData({
    indexCurrent: curIdx
    })
    var videoContextCurrent = wx.createVideoContext(curIdx,this)
    videoContextCurrent.play()
    }
    }
  
},

    
    
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var videoList = [
      {
        id: "1",
        style: 'BBC纪录片',
        logo: '../../images/push/kepu.png',
        logoname: '饮食健康的真相',
        videotitle: '超市里的新鲜蔬菜和冷冻蔬菜，哪种营养更高？',
        coverUrl: '../../images/push/cover/3.png',
        videoUrl: 'cloud://test-5gwxfg0see31cde1.7465-test-5gwxfg0see31cde1-1308718724/1.mp4',
        created_time: '2021/12/05',
        watchNumber: "33333",
      },
      {
        id: "2",
        style: '人文科学',
        logo: '../../images/push/class.png',
        logoname: '食物小史',
        videotitle: '餐桌上的这些食物曾经的样子  野生食物vs现代食物',
        coverUrl: '../../images/push/1.jpg',
        videoUrl: 'cloud://test-5gwxfg0see31cde1.7465-test-5gwxfg0see31cde1-1308718724/2.mp4',
        created_time: '2021/12/05',
        watchNumber: "33333",
      },
      {
        id: "3",
        style: '西贝心理学',
        logo: '../../images/push/class.png',
        logoname: '饮食失调症',
        videotitle: '六种你未必知道的饮食失调症',
        coverUrl: '../../images/push/1.jpg',
        videoUrl: 'cloud://test-5gwxfg0see31cde1.7465-test-5gwxfg0see31cde1-1308718724/3.mp4',
        created_time: '2021/12/05',
        watchNumber: "33333",
      },
    ];
    console.log(videoList);
    //数据显示
    that.setData({
      videoList: videoList,
    })
  },

  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
 
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
 
  },
 /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading() //在标题栏中显示加载
    that.getData();
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    // 提示无数据
    if (this.data.videoList.length < this.data.totalCount) {
     
    }
    else{
      wx.showToast({
        title: '期待下周更新',
      })
    }

  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },
 
  
    /**
   * item 点击-观看次数
  
  bindplay: function(e) {
    var watchNumber = watchNumber+1;
    console.log(watchNumber);
  },   */

  // 点击cover播放，其它视频结束
  videoPlay: function (e) {
    var id = e.currentTarget.id
    /**var watchNumber = e.currentTarget.watchNumber + 1
    console.log(watchNumber)*/
   
    //console.log(this.data.playIndex, id) // 当前播放与当前点击
    if (!this.data.playIndex) { // 当前没有正在播放的视频时
      this.setData({
        playIndex: id
      })
      var videoContext = wx.createVideoContext('index' + id)
      videoContext.play()
    } else {                    // 当前有正在播放的视频先将prev暂停到0s，再播放当前点击的current
      var videoContextPrev = wx.createVideoContext('index' + this.data.playIndex)
      videoContextPrev.seek(0)
      videoContextPrev.pause()
      this.setData({
        playIndex: id
      })
      var videoContextCurrent = wx.createVideoContext('index' + this.data.playIndex)
      videoContextCurrent.play()
    }
  },
  
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
 
  },

  wen:function(e){
    var that = this;
  //添加以上  此页固定显示主界面
    wx.navigateTo({
      url: '../push/push',
    })
  },
  /**
   *运动
   */
  sport:function(e){
    wx.navigateTo({
      url: '../push/sport',
    })
    
  },
 
   
})
 